/*
 * JSF Toolkit Component Framework
 * Copyright (C) 2007 Noah Sloan <iamnoah A-T gmail D0T com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 */
package com.jsftoolkit.gen.writer;

import javax.faces.component.UIComponent;
import javax.faces.event.FacesListener;

/**
 * Interface for classes that generate the code for a component class. An
 * implementation may retain state, so may only be used once.
 * <p>
 * Implementations should prefer the use of {@link ClassWriter} methods to
 * printing code directly whenever possible.
 * 
 * @author noah
 * 
 */
public interface ComponentWriter extends ClassWriter {
	/**
	 * Prints a string constant property.
	 * 
	 * @param name
	 * @param value
	 */
	void printStringConstant(String name, String value);

	/**
	 * Write a private field for the given property.
	 * 
	 * @param type
	 * @param name
	 */
	void printPropertyField(Class<?> type, String name);

	/**
	 * Prints the default constructor.
	 */
	void printConstructor();

	/**
	 * Prints the constants for the component information as recommended by the
	 * JSF spec. i.e. the constants COMPONENT_TYPE, COMPONENT_FAMILY and
	 * DEFAULT_RENDERER_TYPE
	 * 
	 * @param defaultRendererType
	 * @param componentFamily
	 * @param componentType
	 */
	void printCoreConstants(String defaultRendererType, String componentFamily,
			String componentType);

	/**
	 * Prints the getter for the component family. i.e.
	 * {@link UIComponent#getFamily()}
	 */
	void printFamilyGetter();

	/**
	 * Prints a getter and setter for the named property.
	 * 
	 * @param type
	 *            the class of the property
	 * @param name
	 *            the property name
	 * @param defaultValue
	 *            the default value of the property (code string) e.g. "false",
	 *            "new HashMap()", "\"Hello World\"", etc.
	 * @param constantName
	 *            the name of the constant whose value is the attribute name
	 */
	void printAccessors(Class<?> type, String name, String defaultValue,
			String constantName,boolean saveDefault);

	/**
	 * Write out the save and restore state methods based on the information
	 * seen this far. (i.e. the fields written).
	 * 
	 * @param excludeFields
	 *            fields to exclude
	 */
	void printSaveAndRestore(String... excludeFields);

	/**
	 * Prints the necessary code for the given {@link FacesListener}s to attach
	 * to the component.
	 * 
	 * @param listeners
	 */
	public void printListenerCode(
			Iterable<Class<? extends FacesListener>> listeners);
}
